package demo.bocweb.com.sdk.baseApi;

import android.support.annotation.NonNull;

import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * RequestBody 初始化类
 * Created by zhelun on 2018/2/2.
 */

public class RequestHelper {
    RequestBody body;
    Map map;

    public RequestHelper() {
        map = new HashMap<>();
    }

    public static RequestHelper build() {
        return new RequestHelper();
    }

    public RequestHelper add(@NonNull String key, @NonNull Object value) {
        map.put(key, value);
        return this;

    }

    public RequestHelper add(@NonNull String key, @NonNull int value) {
        map.put(key, value);
        return this;

    }

    public RequestHelper add(@NonNull String key, @NonNull boolean value) {
        map.put(key, value);
        return this;

    }

    public RequestHelper add(@NonNull String key, @NonNull String value) {
        map.put(key, value);
        return this;

    }

    public RequestBody create() {
        if (body == null) {
            body = RequestBody.create(MediaType.parse("application/json"), new Gson().toJson(map));
        }
        return body;
    }
}
